///This user control is both used in Admin and Front-End to add a 'Link-To-us' Entry.
///Atuhor   : Kajal Mandal
///Date     : 28 March 2007

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using SiteManager;

public partial class includes_LinkToUs : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        mvLinkToUs.SetActiveView(vwForm);
    }

    /// <summary>
    /// Calls stored procedure to make a new entry and send a mail to the user.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <remarks>
    /// AUTHOR: KAJAL MANDAL
    /// DATE  : 28 MARCH 2007
    /// </remarks>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        SqlParameter[] prm = new SqlParameter[10];
        prm[0] = new SqlParameter("@sno", SqlDbType.BigInt);
        prm[1] = new SqlParameter("@URL", SqlDbType.VarChar,100);
        prm[2] = new SqlParameter("@Title", SqlDbType.VarChar, 200);
        prm[3] = new SqlParameter("@Description", SqlDbType.VarChar, 500);
        prm[4] = new SqlParameter("@Reciprocal_URL", SqlDbType.VarChar, 100);
        prm[5] = new SqlParameter("@Sender", SqlDbType.VarChar, 100);
        prm[6] = new SqlParameter("@EMail", SqlDbType.VarChar, 100);
        prm[7] = new SqlParameter("@isDelete", SqlDbType.Bit);
        prm[8] = new SqlParameter("@status", SqlDbType.Char, 1);
        prm[9] = new SqlParameter("@SUCCESS", SqlDbType.Bit);
        
        prm[0].Value = 0;
        prm[1].Value = txtURL.Text;
        prm[2].Value = txtTitle.Text;
        prm[3].Value = txtDescription.Text;
        prm[4].Value = txtReciprocalURL.Text;
        prm[5].Value = txtName.Text;
        prm[6].Value = txtEMail.Text;
        prm[7].Value = 0;
        prm[8].Value = "V";
        prm[9].Direction = ParameterDirection.Output;
        
        Manager mngr = new Manager(true,"ConnectionString");
        mngr.ExecuteUpdate("MANAGE_LINK_TO_US", prm);

        mvLinkToUs.SetActiveView(vwMessage);

        if (Convert.ToBoolean(prm[9].Value))
        {
            lblMsgHead.ForeColor = System.Drawing.Color.DarkGreen;

            StringBuilder strBody = new StringBuilder(string.Empty);

            strBody.Append("Dear ");
            strBody.Append(txtName.Text);

            strBody.Append("<p>Thank you for submitting your site at www.findadoc.com . Your link submission has been received by our team, and has been added to the queue of links awaiting review.</p>");

            strBody.Append("<p>We are very serious about maintaining the highest standards for links that are accepted in to our website, and so review each submission manually before deciding whether to approve or reject the submission.</p>");

            strBody.Append("<p>This process can take time, although we are constantly looking to speed up the review process as much as possible.</p>");

            strBody.Append("<p>You will receive mail when the application is accepted or rejected.</p>");

            strBody.Append("<p>All the best,<br>");
            strBody.Append("FindaDoc team</p>");

            lblMsgHead.Text = "Thanks!";
            lblMessage.Text = "We have recieved your post successfully!";

            try
            { 
                mngr.sendMail(strBody.ToString(), txtEMail.Text, "FindADoc Team", "Link Submission Received", "info@findadoc.com", ""); 
            }
            catch(Exception excp)
            {
                mngr.sendMail(excp.Message, "synapsetesting@gmail.com", "FindADoc Team", "ERROR - Link Submission", "info@findadoc.com", "");
            }
        }
        else
        {
            lblMsgHead.ForeColor = System.Drawing.Color.Red;
            lblMsgHead.Text = "Sorry!";
            lblMessage.Text = "Due to some technical problem, we are unable to receive your post!";
        }

        mngr = null;

        return;
    }
}
